import {Component, OnInit} from '@angular/core';
import {ListWmsStockTransferComponent} from '../list-wms-stock-transfer.component';
import {Zero3Option} from '../../../../../frame/enum/zero3-option';
import {WmsStockTransfer, WmsStockTransferCondition} from '../../wms-stock-transfer.type';
import * as fa from '@fortawesome/free-solid-svg-icons';
import {Services} from '../../../../../frame/module/services';
import {WmsWarehouseManageCondition} from '../../../wms-warehouse-manage/wms-warehouse-manage.type';
import {isNullOrUndefined} from "util";
import {BaseGoodsCondition} from '../../../../goods-management/goo-base-goods/base-goods.type';

@Component({
    selector: 'app-search-list-wms-stock-transfer',
    templateUrl: './search-list-wms-stock-transfer.component.html',
    styleUrls: ['./search-list-wms-stock-transfer.component.css']
})
export class SearchListWmsStockTransferComponent implements OnInit {

    // func = this.upper.func;

    zero3Option = Zero3Option;

    condition = new WmsStockTransferCondition();
    domain: WmsStockTransfer = new WmsStockTransfer();

    extend = {
        keyup: (event) => {
            // T-O-D-O 51 # err
            if (event.keyCode > 32 || event.keyCode === 8) {
                this.listWmsStockTransfer.func.list.click(event);
            }
        },
        condition: {
            inWareHoseName: {
                items: [],
                nickname: '调出仓库',
                // value: '',
                change: (event) => {
                    // this.condition.serAuditList = [];
                    // console.log(this.field.serAudit.value);
                    // this.condition.serAuditList = this.field.serAudit.value.split(',');
                    console.log(this.condition);
                }
            },
            outWarehouseName: {
                items: [],
                nickname: '调入仓库',
                // value: '',
                change: (event) => {
                    // this.condition.serAuditList = [];
                    // console.log(this.field.serAudit.value);
                    // this.condition.serAuditList = this.field.serAudit.value.split(',');
                    console.log(this.condition);
                }
            },
            serAudit: {
                icon: fa.faList,
                nickname: '全部状态',
                // value: '',
                change: (event) => {
                    // this.condition.serAuditList = [];
                    // console.log(this.field.serAudit.value);
                    // this.condition.serAuditList = this.field.serAudit.value.split(',');
                    console.log(this.condition.serAuditList);
                }
            },
            creator: {
                icon: fa.faCalendar,
                nickname: '商品名称',
                value: () => {
                    return this.condition.serMemo;
                },
                keyup: (event) => {
                    this.condition.serMemo = event.target.value;
                    this.extend.keyup(event);
                }
            },
            serMemo: {
                icon: fa.faPen,
                nickname: '商品编号',
                value: () => {
                    return this.condition.serMemo;
                },
                keyup: (event) => {
                    this.condition.serMemo = event.target.value;
                    this.extend.keyup(event);
                }
            },

        },
    };

    constructor(public listWmsStockTransfer: ListWmsStockTransferComponent) {
        listWmsStockTransfer.search = this;
    }

    ngOnInit() {
        Services.wmsWarehouseManage.list(new WmsWarehouseManageCondition(), {
            page: 0,
            size: 999,
            orders: 'createTime-desc,serNum-asc'
        }).subscribe(item => {
            if (!isNullOrUndefined(item) && item.code === 'success') {
                console.log(item);
                this.extend.condition.inWareHoseName.items = [];
                this.extend.condition.outWarehouseName.items = [];
                item.page.content.forEach(wmsWarehouseManage => {
                    this.extend.condition.inWareHoseName.items.push(
                        {id: wmsWarehouseManage.serName, name: wmsWarehouseManage.serName}
                    );
                    this.extend.condition.outWarehouseName.items.push(
                        {id: wmsWarehouseManage.serName, name: wmsWarehouseManage.serName}
                    );
                });
            }
        });
    }

}
